package ii.zjf.spring;

import ii.zjf.spring.beans.Student;
import ii.zjf.spring.beans.Student1;
import ii.zjf.spring.beans.Student2;
import ii.zjf.spring.comment.Comment1;
import ii.zjf.spring.comment.Config1;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {

    public static void main(String[] args) throws InterruptedException {

        AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring-bean.xml");

        //基于XML的配置方式
        // 1. 普通无参注入bean
        Student student = (Student) context.getBean("student");

        //2 带 init 、destory lazy-init 注入bean
        Student1 student1 = (Student1) context.getBean("student1");

        //3 factory + 构造方法 + 多例 注入bean
        Student2 student2 = (Student2) context.getBean("student2");
        student2.say();

        Thread.sleep(2000);

        Student2 student2_2 = (Student2) context.getBean("student2");
        student2_2.say();

        //基于注解的配置方式
        Comment1 comment1 = (Comment1) context.getBean("comment1");
        comment1.say();

        //基于java类的配置
        Config1 config1 = (Config1) context.getBean("config1");

        context.close();

    }

}
